//请求基础路径
const BASE_PATH = 'http://127.0.0.1:9002'
//图片基础路径
export const IMG_BASE_PATH = 'http://127.0.0.1:9002';

//会员接口基础路径
const MEMBER_BASE_PATH = '/wemall/member/api';
//会员收件地址基础路径
const ADDRESS_BASE_PATH = '/wemall/member/address/api';

//商品接口基础路径
const PRODUCT_BASE_PATH = '/wemall/product/api';

//收藏接口基础路径
const COLLECT_BASE_PATH = '/wemall/member/collect/api';
//购物车接口基础路径
const CART_BASE_PATH = '/wemall/member/cart/api';
//请求接口
const apis = {
    member: {
        /*发送注册邮件验证码接口*/
        sendRegCode: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/send_register_code`,
            type: 'POST'
        },
        /*会员注册接口*/
        register: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/register`,
            type: 'POST'
        },
        /*会员登录接口*/
        login: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/login`,
            type: 'POST'
        },
        /***
         * 会员退出登录接口
         */
        logout: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/logout`,
            type: 'POST',
            authCheck: true //登录检查
        },
        /***
         * 发送找回密码邮件验证码接口
         */
        sendFindPwdCode: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/send_find_password_code`,
            type: 'POST'
        },
        /**重置密码接口*/
        reset: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/reset`,
            type: 'POST'
        },
        /**获取会员信息接口*/
        getInfo: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/info`,
            type: 'GET',
            authCheck: true //登录检查
        },
        /***
         * 设置会员头像接口
         */
        setAvatar: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/set_avatar`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 会员修改密码接口
         */
        modifyPassword: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/modify_pwd`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 会员修改个人信息接口
         */
        modify: {
            url: `${BASE_PATH}${MEMBER_BASE_PATH}/modify`,
            type: 'POST',
            authCheck: true
        },
    },
    address: {
        /***
         * 会员收件地址列表接口
         */
        list: {
            url: `${BASE_PATH}${ADDRESS_BASE_PATH}/list`,
            type: 'GET',
            authCheck: true
        },
        /***
         * 会员收件地址添加接口
         */
        create: {
            url: `${BASE_PATH}${ADDRESS_BASE_PATH}/create`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 会员收件地址删除接口
         */
        delete: {
            url: `${BASE_PATH}${ADDRESS_BASE_PATH}/remove`,
            type: 'DELETE',
            authCheck: true
        },
        /***
         * 会员收件地址修改接口
         */
        modify: {
            url: `${BASE_PATH}${ADDRESS_BASE_PATH}/modify_by_id`,
            type: 'POST',
            authCheck: true
        },
    },
    /**商品**/
    product: {
        /** 商品分类接口*/
        categoryList: {
            url: `${BASE_PATH}/wemall/product/category/api/list`,
            type: 'GET'
        },
        /***
         * 商品列表接口
         */
        productList: {
            url: `${BASE_PATH}${PRODUCT_BASE_PATH}/list`,
            type: 'GET'
        },
        /***
         * 商品详情接口
         */
        details: {
            url: `${BASE_PATH}${PRODUCT_BASE_PATH}/details/{id}`,
            type: 'GET'
        }
    },
    /**收藏**/
    collect: {
        /***
         * 收藏商品列表接口
         */
        getCollectList: {
            url: `${BASE_PATH}${COLLECT_BASE_PATH}/list`,
            type: 'GET',
            authCheck: true
        },
        /***
         * 收藏商品添加接口
         */
        add: {
            url: `${BASE_PATH}${COLLECT_BASE_PATH}/add`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 收藏商品删除接口
         */
        delete: {
            url: `${BASE_PATH}${COLLECT_BASE_PATH}/del`,
            type: 'DELETE',
            authCheck: true
        },
        /***
         * 是否收藏该商品接口
         */
        contains: {
            url: `${BASE_PATH}${COLLECT_BASE_PATH}/contains`,
            type: 'GET',
            authCheck: true
        }
    },
    /**购物车*/
    cart: {
        /***
         * 购物车列表接口
         */
        list: {
            url: `${BASE_PATH}${CART_BASE_PATH}/list`,
            type: 'GET',
            authCheck: true
        },
        /***
         * 购物车添加接口
         */
        add: {
            url: `${BASE_PATH}${CART_BASE_PATH}/add`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 购物车删除接口
         */
        remove: {
            url: `${BASE_PATH}${CART_BASE_PATH}/remove`,
            type: 'DELETE',
            authCheck: true
        },
        /***
         * 购物车更新接口
         */
        modify: {
            url: `${BASE_PATH}${CART_BASE_PATH}/modify`,
            type: 'POST',
            authCheck: true
        },
        /***
         * 购物车清空接口
         */
        clear: {
            url: `${BASE_PATH}${CART_BASE_PATH}/clear`,
            type: 'DELETE',
            authCheck: true
        },

    }
}

//获取需要进行登录检查接口
export function getAuthCheckUrls() {
    let authCheckUrls = [];
    for (let module in apis) {
        for (let api in apis[module]) {
            if (apis[module][api].authCheck) {
                authCheckUrls.push(apis[module][api].url);
            }
        }
    }
    return authCheckUrls;
}

export default apis;
